import input from '../internal/mixins/input';

export default {
  name: 'co-input',
  mixins: [input],
  methods: {
    handleFocus (e) {
      this.isFocused = true;
      this.$emit('focus', e);
    },
    handleBlur (e) {
      this.isFocused = false;
      this.$emit('blur', e);
    },
    createElement (h) {
      return h('input', {
        class: 'co-input__element',
        attrs: {
          ...this.$attrs,
          disabled: this.disabled
        },
        domProps: {
          value: this.value
        },
        on: {
          ...this.$listeners,
          input: (e) => this.$emit('input', e.target.value, e),
          change: (e) => this.$emit('change', e.target.value, e),
          focus: this.handleFocus,
          blur: this.handleBlur
        }
      });
    }
  },
  render (h) {
    return this.createInput(h, {
    }, [
      this.createElement(h)
    ]);
  }
};
